using System;
using System.Collections.Generic;
using System.Text;

namespace LibGreen.Jabber.ProtocolElements.SaslElements
{
    /// <summary>
    /// Defines a &lt;response&gt; element
    /// </summary>
    class ResponseElement
    {
        /// <summary>
        /// The xmlns of the &lt;response&gt; element
        /// </summary>
        private static string XMLNS = "urn:ietf:params:xml:ns:xmpp-sasl";

        /// <summary>
        /// Creates a new &lt;response&gt; element originating from the client
        /// </summary>
        /// <param name="plaintextData">The data to send in response to a challenge</param>
        /// <returns>A new &lt;response&gt; element</returns>
        public static Element Create(string plaintextData)
        {
            Dictionary<string, string> attributes = new Dictionary<string, string>(2);
            attributes["xmlns"] = XMLNS;
            string base64data = Convert.ToBase64String(Encoding.UTF8.GetBytes(plaintextData));
            return Element.CreateElement("response", attributes, base64data);
        }
    }
}
